pp108 : Object Relational Mapping in WS-AppServer

Object Relational Mapping in WS-AppServer

This topic describes object relational mapping in WS-AppServer.


Object relational mapping is a programming technique that links relational databases to objects that are created using an object-oriented language (for example, Java). The objects are designed to establish either one-to-one or one-to-many mapping with a database table. Object relational mapping is defined in an XML document, which can be easily customized as required.

WS-AppServer is designed to work with any relational database and use the details to create and maintain object-relation models. Each row in the database is mapped to an instance of the business object and is called a 'tuple' or a record. The different columns that contain various information constitute the 'attributes' of the object. Thus, when the information in the database is translated into an XML object, it is represented in a <tuple> structure.
Consider an example of a database table called
Departmental Store. A record in that table is called "Item", which is represented by an XML object as shown in the following code sample.

<tuple>
    <Item>
        <ItemID>001</ItemID>
        <ItemName>Apple</ItemName>
        <ItemQuantity>10</ItemQuantity>
        <ItemPrice>15</ItemPrice>
    </Item>
</tuple>

The various attributes, such as ItemID, ItemName, ItemQuantity, and ItemPrice are the columns in that table. WS-AppServer goes one step ahead and facilitates wrapping of the XML object into a Java object. As a result, a Java class is created, which can easily interact with any Java-based web application. Once the Java class is created, it is easier for a Java application to communicate with the database and persist data without any other dependency. The following sample code represents the Java object that is created.

public abstract class ItemBase extends com.cordys.department.StateBusObject { public final static String ATTR_Item_Id = "Item_Id"; public final static String ATTR_Item_Name = "Item_Name"; public final static String ATTR_Item_Quantity = "Item_Quantity"; public final static String ATTR_Item_Price = "Item_Price"; }

In an application, there may be several such individual objects that need to be mapped together. Following are the different types of mappings that may be required by the application:

  • One-to-one - Establishes a relationship between two objects. In this case, the Primary Key of one object becomes the Foreign Key in the other object.
  • One-to-many - Links one object to many objects. In this case, one object is embedded in multiple objects as a foreign key column.
  • Many-to-one - Links many objects to one object. In this case, different objects are embedded in a single object as the foreign key column.

    In Process Platform, the task of creating objects and establishing relationships between them is achieved effortlessly through WS-AppServer. It facilitates easy creation of objects that are mapped to the database tables. It establishes relationship among the objects based on their Primary and Foreign Keys. The objects are easily enveloped into Java classes, which can be readily used by the applications. The amount of time taken to convert database tables into objects and later into Java classes is very minimal. As a result, WS-AppServer emerges as a simple platform for rapid application development using relational data.

Related concepts

BusObjects

Related reference

Mapping of BusObjects in WS-AppServer

Related information

Extending Business Logic in WS-AppServer Generated Applications